package sy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sy.pageModel.BaseEntity;
import sy.pageModel.DataGrid;
import sy.pageModel.Json;
import sy.pageModel.ServiceEntity;
import sy.service.ServiceServiceI;
import sy.util.StringUtil;

import java.util.List;

/**
 * Created by Administrator on 2016-07-05.
 */
@RequestMapping("serviceController")
@Controller
public class ServiceController {
    @Autowired
    private ServiceServiceI serviceService;

    @RequestMapping("/datagrid.action")
    @ResponseBody
    public DataGrid findListAction(ServiceEntity service){
        return serviceService.findPicDataGird(service);
    }

    @RequestMapping("/add_service.action")
    @ResponseBody
    public Json addServiceAction(ServiceEntity service){
        int rows=0;
        try {
            rows=serviceService.addServiceAction(service);
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"添加");
        return js;
    }
    @RequestMapping("/edit_service.action")
    @ResponseBody
    public Json editServiceAction(ServiceEntity service){
        int rows=0;
        try {
            rows=serviceService.editServiceAction(service);
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"修改");
        return js;
    }
    @RequestMapping("/del_service.action")
    @ResponseBody
    public Json delServiceAction(ServiceEntity service){
        int rows=0;
        try {
            rows=serviceService.deleteServiceAction(service);
        } catch (Exception e) {
            e.printStackTrace();
            rows=0;
        }
        Json js= StringUtil.findJson(rows,"删除");
        return js;
    }

    @RequestMapping("/find_base.action")
    @ResponseBody
    public Json findBaseAction(ServiceEntity service){
        Json js=new Json();
        js.setList(serviceService.findBaseList());
        return js;
    }
    @RequestMapping("/find_base1.action")
    @ResponseBody
    public List<ServiceEntity> findBaseAction1(ServiceEntity service){
        return serviceService.findBaseList();
    }
}